import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

/* Layout */
import Layout from '@/layout';

export const constantRoutes = [
	{
		path: '/login',
		component: () => import('@/views/login/index'),
		hidden: true,
		meta: { auth: 'true', white: true }
	},
	{
		path: '/404',
		component: () => import('@/views/404'),
		hidden: true,
		meta: { auth: 'true', white: true }
	},
	{
		path: '/',
		component: Layout,
		redirect: '/main',
		meta: { auth: 'true', white: true },
		children: [
			{
				path: 'main',
				name: '首页',
				component: () => import('@/views/dashboard/index'),
				meta: { title: '首页', icon: 'dashboard', affix: true }
			},
			{
				path: '/changePass',
				component: () => import('@/views/changePass'),
				hidden: true,
				meta: { auth: 'true', white: true }
			}
		]
	},
	{
		path: '/system',
		component: Layout,
		name: '系统管理',
		meta: { title: '系统管理', icon: 'el-icon-s-help', auth: 'true' },
		children: [
			{
				path: '/system/account',
				name: '账号管理',
				component: () => import('@/views/system/account'),
				meta: { title: '账号管理', auth: 'true', icon: 'el-icon-help' }
			},
			{
				path: '/system/role',
				name: '角色管理',
				component: () => import('@/views/system/role'),
				meta: { title: '角色管理', auth: 'true', icon: 'el-icon-s-check' }
			},
			{
				path: '/system/menu',
				name: '菜单管理',
				component: () => import('@/views/system/menu'),
				meta: { title: '菜单管理', auth: 'true', icon: 'el-icon-menu' }
			},
			{
				path: '/system/dict',
				name: '字典管理',
				component: () => import('@/views/system/dict'),
				meta: { title: '字典管理', auth: 'true', icon: 'el-icon-s-data' }
			}
		]
	},
	{ path: '*', redirect: '/404', hidden: true, meta: { auth: 'true', white: true } }
];

const createRouter = () =>
	new Router({
		scrollBehavior: () => ({ y: 0 }),
		routes: constantRoutes
	});

const router = createRouter();

export function resetRouter() {
	const newRouter = createRouter();
	router.matcher = newRouter.matcher;
}

export default router;
